#!/usr/bin/env php
<?php
define('APPLICATION_ENV','production');
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (	('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
/** Zend_Application */
require_once 'Doctrine.php';

//require 'Zend/Loader.p
require_once 'Zend/Application.php';

$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);

$tempArr = explode("=",end($_SERVER['argv']));
if (count($tempArr)<2) {
    $errorMessage =  $_SERVER['argv'][0].' '.$_SERVER['argv'][1] . " module=module_name\n";
    throw new Doctrine_Exception($errorMessage);
    //$ss = new Exception($errorMessage);
    //echo $ss; exit;
}
$module = $tempArr[1];
$modulePath = APPLICATION_PATH.'/modules/'.$module;
$options = array(
            'data_fixtures_path' => $modulePath . '/data/fixtures',
            'models_path'        => $modulePath . '/model',
            'migrations_path'    => $modulePath . '/data/migrations',
            'sql_path'           => $modulePath . '/data',
            'yaml_schema_path'   => $modulePath . '/data/schema',
            'generate_models_options' => array(
            'pearStyle' => false,
    //        'generateTableClasses' => true,
            'generateBaseClasses' => true,
            'classPrefixFiles' => false,
            'baseClassPrefix' => 'Base',
            'classPrefix' => ucfirst($module).'_Model_',
            'baseClassesDirectory' => null,
));


$manager = $application->getBootstrap()
->bootstrap('doctrine')->getResource('doctrine');
$manager->setAttribute(Doctrine::ATTR_MODEL_LOADING,
Doctrine::MODEL_LOADING_AGGRESSIVE);
$cli = new Doctrine_Cli($options);

$cli->run($_SERVER['argv']);

